package com.tanhua.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.ReportMapper;
import com.tanhua.model.domain.Report;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class ReportApiImpl implements ReportApi{
    @Autowired
    private ReportMapper reportMapper;



    @Override
    public Report findByUserId(Long userId) {
        LambdaQueryWrapper<Report> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Report::getUserId,userId);
        return reportMapper.selectOne(lqw);
    }

    @Override
    public void save(Report report) {
        reportMapper.insert(report);
    }

    @Override
    public void updateById(Report byUserId) {
        reportMapper.updateById(byUserId);
    }

    @Override
    public List<Long> getUserIdByConclusionId(int id) {
        LambdaQueryWrapper<Report> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id!=0,Report::getConclusionId,id);
        List<Report> reports = reportMapper.selectList(lqw);
        return CollUtil.getFieldValues(reports, "userId",Long.class);
    }
}
